<template>
  <base-breadcrumb>
    <searchData :search-data="searchArr" @search="search" />
    <a-card :bordered="false">
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
        :exportConfig="{ use: true,select: '导出选中',all: '导出全部'}"
        :exportPermission="{  select: 'mm_039_der_01',all: 'mm_039_der_02'}"
        :statisticsConfig="{use: true,statistics}"
        :is-show-delete-count="false"
      >
        <template slot="prefix" slot-scope="text, record, index">
          <a-button v-btn-permission="'mm_039_add_05'" type="primary" @click="handleEdit()">新增</a-button>
        </template>
        <template slot="index" slot-scope="text, record, index">{{ index + 1 }}</template>
        <template slot="auditStatusStr" slot-scope="text, record, index">
          <list-status :status="record.auditStatus" :text="text" />
        </template>
        <div slot="operation" slot-scope="text, record, index">
          <!--          <MoreButton :is-span="true">-->
          <MoreButton>
            <a @click="handleEdit(record.id, 'look')">查看</a>
            <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
              <a v-btn-permission="'mm_039_edi_03'" @click="() => handleEdit(record.id, 'edit')">编辑</a>
              <a v-btn-permission="'mm_039_del_04'" @click="() => del(record.id)">删除</a>
            </template>
            <approval-button :id="record.id" :status="record.auditStatus"
                             v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'REVOKEIN' || record.auditStatus === 'REVOKE' || record.auditStatus === 'ABOLISH' || record.auditStatus === '1' || record.auditStatus === '3' || record.auditStatus === 'COMMIT'|| record.auditStatus === '2' "
            />
          </MoreButton>
          <!--          </MoreButton>-->
        </div>
      </list-table>

    </a-card>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import Api from '@/api/material/inventory/checkPlan'
import MoreButton from '@/components/MoreButton'

export default {
  name: 'a' + Date.now(),
  components: { MoreButton },
  data: function() {
    return {
      loading: false,
      queryParam: {},
      searchArr: [
        // 搜索框
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // { name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany },
        // { name: '项目名称', type: SelectProject, valueKey: 'projectId', keyValue: 'branchComId'  },
        { name: '盘点计划编号', value: 'inventoryPlanCode', type: 'input' },
        { name: '盘点计划名称', value: 'inventoryPlanName', type: 'input' },
        { name: '盘点编号', value: 'inventoryCodeAll', type: 'input' },
        { name: '状态', value: 'auditStatus', type: 'select', data: this.STATUS },
        { name: '创建人', value: 'creatorName', type: 'input' },
        { name: '创建时间', value: 'createTime', type: 'dateRangeFormat' }
      ],
      columns: [
        { title: '序号', dataIndex: 'index', scopedSlots: { customRender: 'index' }, width: 70 },
        { title: '所属分公司', dataIndex: 'branchComName', width: 150 },
        // { title: '项目名称', dataIndex: 'projectName', width: 150 },
        { title: '盘点计划编号', dataIndex: 'inventoryPlanCode', width: 140 },
        { title: '盘点计划名称', dataIndex: 'inventoryPlanName', width: 160 },
        { title: '盘点编号', dataIndex: 'inventoryCodeAll', width: 140 },
        { title: '创建人', dataIndex: 'creatorName', width: 140 },
        { title: '创建时间', dataIndex: 'createTime', width: 140 },
        {
          title: '状态',
          width: this.STATUS_WIDTH,
          dataIndex: 'auditStatusStr',
          scopedSlots: { customRender: 'auditStatusStr' }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 220,
          fixed: 'right',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      loadData: p => {
        let q = Object.assign({}, p, { query: this.queryParam })
        Api.count(q).then(res => {
          this.statistics = res.data
        })
        return Api.findListByMain(q)
      },
      statistics: {}
    }
  },
  methods: {
    search(val = {}) {
      this.queryParam = val
      this.$refs.table.refresh()
    },
    del(id) {
      this.$delList3(Api.deleteById, this.search, { id })
    },
    handleEdit(id = '', pageType = 'add') {
      this.$router.push({
        path: '/material/inventory/checkPlanAdd',
        query: {
          id,
          pageType
        }
      })
    }
  }
}
</script>
